View Javadoc

1   // BootstrapHeapAddress.java, created Wed Sep 18  1:22:47 2002 by joewhaley
2   // Copyright (C) 2001-3 John Whaley <jwhaley@alum.mit.edu>
3   // Licensed under the terms of the GNU LGPL; see COPYING for details.
4   package joeq.Bootstrap;
5   
6   import joeq.Class.PrimordialClassLoader;
7   import joeq.Class.jq_Class;
8   import joeq.Memory.Address;
9   import joeq.Memory.HeapAddress;
10  import jwutil.strings.Strings;
11  import jwutil.util.Assert;
12  
13  /***
14   * BootstrapHeapAddress
15   *
16   * @author  John Whaley <jwhaley@alum.mit.edu>
17   * @version $Id: BootstrapHeapAddress.java 1941 2004-09-30 03:37:06Z joewhaley $
18   */
19  public class BootstrapHeapAddress extends HeapAddress implements BootstrapAddress {
20  
21      public static BootstrapHeapAddressFactory FACTORY = new BootstrapHeapAddressFactory(SinglePassBootImage.DEFAULT);
22      
23      public static class BootstrapHeapAddressFactory extends HeapAddressFactory {
24          SinglePassBootImage bi;
25          public BootstrapHeapAddressFactory(SinglePassBootImage bi) {
26              Assert._assert(bi != null);
27              this.bi = bi;
28          }
29          public int size() { return 4; }
30          public int logSize() { return 2; }
31          public int pageAlign() { return 12; }
32          public HeapAddress getNull() { return NULL; }
33          public HeapAddress addressOf(Object o) {
34              //if (o == null) return NULL;
35              return bi.getOrAllocateObject(o);
36          }
37          public HeapAddress address32(int v) {
38              return new BootstrapHeapAddress(v);
39          }
40          public static final BootstrapHeapAddress NULL = new BootstrapHeapAddress(0);
41      }
42      
43      public final int value;
44      
45      public BootstrapHeapAddress(int value) { this.value = value; }
46      
47      public Address peek() { Assert.UNREACHABLE(); return null; }
48      public byte    peek1() { Assert.UNREACHABLE(); return 0; }
49      public short   peek2() { Assert.UNREACHABLE(); return 0; }
50      public int     peek4() { Assert.UNREACHABLE(); return 0; }
51      public long    peek8() { Assert.UNREACHABLE(); return 0; }
52      
53      public void poke(Address v) { Assert.UNREACHABLE(); }
54      public void poke1(byte v) { Assert.UNREACHABLE(); }
55      public void poke2(short v) { Assert.UNREACHABLE(); }
56      public void poke4(int v) { Assert.UNREACHABLE(); }
57      public void poke8(long v) { Assert.UNREACHABLE(); }
58      
59      public Address offset(int offset) { return new BootstrapHeapAddress(value+offset); }
60      public Address align(int shift) {
61          int mask = (1 << shift) - 1;
62          return new BootstrapHeapAddress((value+mask)&~mask);
63      }
64      public int difference(Address v) { return this.value - v.to32BitValue(); }
65      public boolean isNull() { return value == 0; }
66      
67      public int to32BitValue() { return value; }
68      public String stringRep() { return Strings.hex8(value); }
69      
70      public static final jq_Class _class;
71      static {
72          _class = (jq_Class) PrimordialClassLoader.loader.getOrCreateBSType("Ljoeq/Bootstrap/BootstrapHeapAddress;");
73      }
74  }